
layui.use(['form', 'layedit', 'laydate',"table",'upload'], function() {
    var $ = layui.jquery
        , upload = layui.upload;
    var table = layui.table;
    var form = layui.form
        , layer = layui.layer
        , layedit = layui.layedit
        , laydate = layui.laydate;

    //日期
    laydate.render({
        elem: '#searchStartTime'
        ,type: 'datetime'
    });
    laydate.render({
        elem: '#searchEndTime'
        ,type: 'datetime'
    });
    //监听工具条
    table.on('tool(demo)', function(obj){
        var data = obj.data;
        if(obj.event === 'detail'){
            layer.msg('ID：'+ data.id + ' 的查看操作');
        } else if(obj.event === 'del'){
            layer.confirm('确定删除吗?', function(index){
                $.ajax({
                    url:"/clubController/delete",
                    type:"POST",
                    data:{id:data.id},
                    dataType:"json",
                    success:function(data){
                        if (data.code == -1){
                            top.location.href="/pageController/login"

                        }
                        if(data.ret ==0){
                            layer.alert('删除成功', {icon: 1}, function(index){
                                layer.closeAll("page");
                                layer.close(index);
                                var curr = sessionStorage.getItem("curr");
                                table.reload('testReload',{page:{curr:curr}});
                            });
                        }else{
                            layer.alert('删除失败', {icon: 5});
                        }
                    }
                })
                layer.close(index);

            });
        } else if(obj.event === 'edit'){


            var  width=($(window).width()*0.8);
            var height=($(window).height()*0.9);
            layer.open({
                type: 1,
                closeBtn: 1,
                area: [width + 'px', height + 'px'],//大小
                content: $("#topic"),
                skin: "layui-layer-molv",
                title:  "话题:"+data.name
            })
        }
    });

    //方法级渲染
    table.render({
        elem: '#table'
        ,url: '/searchController/searchList'
        ,cols: [
            [
                {type:'numbers', title: '序',align:"center"},

                { field: 'word', title: '搜索词',align:"center"},

                { field: 'userID', title: '用户ID',align:"center",templet: function(d){
                    if (d.userID >0){
                        return  d.userID;
                    }else{
                        return "--"
                    }

                }},

                { field: 'nickName', title: '用户昵称',align:"center"},

                {field: 'createTime', title: '时间',align:"center",templet: function(d){
                    if(isNull(d.createTime)){
                        return "--";
                    }
                    return getFormatDateByLong(d.createTime, "yyyy-MM-dd hh:mm:ss");
                }}
            ]
        ]
        ,id: 'testReload'
        ,page: true
        ,done:function (res, curr, count) {
            sessionStorage.setItem("curr",curr)
        }
    });

    var $ = layui.$, active = {
        reload: function(){

            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                        name: $('input[name="name"]').val(),
                        userId:$('#selectUserId').val(),
                        word: $('input[name="word"]').val(),
                    startTime: $('#searchStartTime').val(),
                    endTime: $('#searchEndTime').val()

                }
            });
        }
    };

    $('.demoTable .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });


});



